package com.vr.xuecheng.content.controller;

import com.vr.xuecheng.base.response.Result;
import com.vr.xuecheng.content.model.entity.TeachPlanMedia;
import com.vr.xuecheng.content.service.ITeachPlanMediaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hzh
 * @date 2025/04/11
 */
@Slf4j
@Tag(name = "课程计划媒资关联信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/teachplan/media")
public class TeachPlanMediaController {
    private final ITeachPlanMediaService teachPlanMediaService;
    @Operation(summary = "获取课程计划媒资的媒资id")
    @GetMapping("/{course-id}/{teachplan-id}")
    public Result<String> getTeachPlanMedia(@PathVariable("course-id") Long courseId, @PathVariable("teachplan-id") Long teachplanId) {
        TeachPlanMedia teachPlanMedia = teachPlanMediaService
                .lambdaQuery()
                .eq(TeachPlanMedia::getTeachplanId, teachplanId)
                .eq(TeachPlanMedia::getCourseId, courseId)
                .one();
        if (teachPlanMedia == null) {
            return Result.toResult(false);
        }
        return Result.toResult(true, teachPlanMedia.getMediaId());
    }
}
